<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style type="text/css">
    .el-main{
        position: absolute;
        top: 70px;
        bottom: 0px;
        left: 200px;
        right: 10px;
        padding: 0;
    }
    </style>
</head>
<body class="hold-transition skin-purple sidebar-mini">
    <div id="app">
        <el-container>
            <el-header  class="main-header" style="height:70px;">
                <nav class="navbar navbar-static-top" :class=''>
                    <!-- Logo -->
                    <a href="#" class="logo" style="text-align:center">
                        <span class="logo-lg"><img src="../img/logo.png"></span>
                    </a>
                    <div class="right-menu">
                        <span class="help"><i class="fa fa-exclamation-circle" aria-hidden="true"></i>帮助</span>
                        <el-dropdown class="avatar-container right-menu-item" trigger="click">
                            <div class="avatar-wrapper">
                                <img src="../img/user2-160x160.jpg" class="user-avatar">
                                {{username}}
                            </div>
                            <el-dropdown-menu slot="dropdown">
                                <div @click="handlePassword">
                                    <el-dropdown-item divided >
                                        <span style="display:block;" >修改密码</span>
                                    </el-dropdown-item>
                                </div>
                                <a href="/logout.do">
                                    <el-dropdown-item divided>
                                        <span style="display:block;">退出</span>
                                    </el-dropdown-item>
                                </a>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </div>
                </nav>
            </el-header>
            <el-container>
                <el-aside width="200px">
                    <el-menu>
                        <el-submenu v-for="menu in menuList" :index="menu.path">
                            <template slot="title">
								<i class="fa" :class="menu.icon"></i>
                                {{menu.name}}
                            </template>
                            <template v-for="child in menu.children">
                                <el-menu-item :index="child.path">
                                    <a :href="child.linkUrl" target="right">{{child.name}}</a>
                                </el-menu-item>
                            </template>
                        </el-submenu>
                    </el-menu>
                </el-aside>
                <el-container>
                    <iframe name="right" class="el-main" src="ordersetting.html" width="100%" height="580px" frameborder="0"></iframe>
                </el-container>
            </el-container>
        </el-container>
        <!--修改密码弹层-->
        <div class="change-form">
            <el-dialog title="修改密码" :visible.sync="popChange" align="center">
                <el-form ref="dataChangeForm" :model="user" :rules="rules2" label-position="right"
                         label-width="100px">
                    <el-row>
                        <el-col :span="20">
                            <el-form-item label="用户名">
                                <el-input v-model="user.username" disabled/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="20">
                            <el-form-item label="原密码" prop="oldPassword">
                                <el-input v-model="user.oldPassword" type="password"></el-input>
                            </el-form-item>
                        </el-col>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="20">
                            <el-form-item label="新密码" prop="password">
                                <el-input v-model="user.password" type="password"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="20">
                            <el-form-item label="确认密码">
                                <el-input v-model="conPassword" type="password"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="popChange=false">取消</el-button>
                    <el-button type="primary" @click="changePassword()">确定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script>
    new Vue({
        el: '#app',
        data:{
            conPassword: null,
            username:null,
            menuList:[],
            popChange: false,
            user: {},
            rules2: {//校验规则 饿了么ui规定的
                password: [{required: true, message: '新密码为必填项', trigger: 'blur'}],
                oldPassword: [{required: true, message: '原密码为必填项', trigger: 'blur'}]
            }
        },
        methods:{
            //点击修改密码
            handlePassword() {
                this.popChange = true;
            },
            //修改密码
            changePassword() {
                //    先判断校验是否通过
                this.$refs['dataChangeForm'].validate((valid) => {
                    if (valid) {
                        //判端两次新密码是否相同
                        var password1 = this.user.password;
                        var password2 = this.conPassword;
                        if (password1 == password2) {
                            //   发送ajax请求
                            axios.post("/user/modify.do", this.user).then((res) => {
                                if (res.data.flag) {
                                    //修改密码成功
                                    this.$message({
                                        type: 'success',
                                        message: res.data.message
                                    });

                                    top.location.href = "/logout.do";
                                } else {
                                    this.$message.error(res.data.message + "【" + res.data.data + "】");
                                }
                            });
                        } else {
                            this.$message.error("两次密码不一致");
                        }
                    } else {
                        this.$message.error("表单数据校验失败");
                        return false;
                    }
                });
            },
        },
        created(){
            //发送ajax请求，获取当前登录用户的用户名，用于页面展示
            axios.get("/user/getLoginUsername.do").then((res) => {
                this.username = res.data.data;
                axios.get("/menu/findMenuByUsername.do",{params:{"username":this.username}}).then((res) => {
                    if(res.data.flag){
                        this.menuList=res.data.data;
                    }else{
                        this.$message(res.data.message);
                    }
                })
            });
            //回显修改用户表单的用户名
            axios.post("/user/showUsername.do").then((res) => {
                this.user.username = res.data.data;
            });
        }
    });
    $(function() {
            var wd = 200;
            $(".el-main").css('width', $('body').width() - wd + 'px');
    });
</script>
</html>
